﻿namespace WMS_Goodsinfo.ErrorCode
{
    public class ApiResult<T>
    {
        /// <summary>
        /// 响应状态
        /// </summary>
        public StatusEnum Code { get; set; }
        /// <summary>
        /// 响应消息
        /// </summary>
        public string Message { get; set; }
        /// <summary>
        /// 响应数据
        /// </summary>
        public T Data { get; set; }

        /// <summary>
        /// 创建成功响应
        /// </summary>
        /// <param name="data">响应数据</param>
        /// <param name="message">响应消息</param>
        /// <returns>成功响应</returns>
        public static ApiResult<T> Success(T data, string message = "操作成功")
        {
            return new ApiResult<T>
            {
                Code = StatusEnum.OK,
                Message = message,
                Data = data
            };
        }

        /// <summary>
        /// 创建错误响应
        /// </summary>
        /// <param name="message">错误消息</param>
        /// <param name="code">错误代码</param>
        /// <returns>错误响应</returns>
        public static ApiResult<T> Error(string message, StatusEnum code = StatusEnum.Error)
        {
            return new ApiResult<T>
            {
                Code = code,
                Message = message,
                Data = default(T)
            };
        }
    }
}
